# -*- coding: utf-8 -*-
# @File  : 进程池.py
# @Author: zbh
# @Date  : 2025/2/19_15:10

import multiprocessing
import os
import time
from multiprocessing import Pool

def math(i):
    print(i**2)


def pool():
    with Pool(processes=4) as pool:  # 创建一个进程池，进程池中的进程数为4
        start = time.time()
        pool.map(math, range(4),chunksize=1)  # 将login函数放入进程池中，range(4)为参数列表，进程池中的进程会依次执行login函数，参数为range(4)中的元素
        stop = time.time()
        print("计算密集型任务，多进程耗时：", round(stop - start, 2))
if __name__ == "__main__":
    pool()



